<template>
    <div class="pie">
        <div :id="'histogram' + cageId" :style="styles"></div>
    </div>
</template>

<script>
import echarts from 'echarts';
export default {
  data () {
    return {
      cageId: parseInt(Math.random() * 100000)
    };
  },
  mounted () {
    this.drawLine();
  },
  props: {
    // 样式
    styles: Object,
    // 参数数据
    paramsData: Array,
    // 提示数据
    xData: Array,
    // 标题
    title: String
  },
  methods: {
    drawLine () {
      let that = this;
      // 基于准备好的dom，初始化echarts实例
      let myChart = echarts.init(document.getElementById('histogram' + that.cageId));
      // 绘制图表
      myChart.setOption({
        color: ['#3398DB'],
        title: {
          text: that.title
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data: that.xData,
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '直接访问',
            type: 'bar',
            barWidth: '60%',
            data: that.paramsData
          }
        ]
      });
    }
  }
};
</script>


<style lang="stylus" scoped>

</style>
